package com.example.flshtarvel.mapper;

import com.example.flshtarvel.vo.RouteVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleRouteMapMapper {
    @Insert("insert into article_route_map(article_id,route_id) values(#{articleId},#{routeId})")
    public int insertArticleRouteMap(String articleId,String routeId);

    @Delete("delete from article_route_map where article_id=#{articleId} and route_id=#{routeId}")
    public int deleteArticleRouteMap(String articleId,String routeId);

    @Delete("delete from article_route_map where route_id=#{routeId}")
    public int deleteArticleRouteMapByRouteId(String routeId);

    //@Select("select * from article_route_map,route where article_route_map.route_id=route.route_id and article_id=#{articleId}")
    @Select("select route.*,likeView.like_count,collectView.collect_count  from route,article_route_map, (select route.route_id,count(love.message_id) as like_count from route  LEFT JOIN love on route.route_id = love.message_id GROUP BY(route.route_id)) likeView, (select route.route_id,count(collect.message_id) as collect_count  from route  LEFT JOIN collect on route.route_id = collect.message_id GROUP BY(route.route_id)) collectView where route.route_id = likeView.route_id and route.route_id = collectView.route_id and article_route_map.route_id=route.route_id and article_id=#{articleId}")
    public List<RouteVo> seleteArticleRouteMapByArticleId(String articleId);
}
